package gxmzu.gxmzuproject.controller;

import gxmzu.gxmzuproject.param.MiniCode2SessionQueryParam;
import gxmzu.gxmzuproject.service.MiniUserInfoService;
import gxmzu.gxmzuproject.param.MiniUserInfoQueryParam;
import gxmzu.gxmzuproject.vo.MiniLoginInfoQueryVo;
import gxmzu.gxmzuproject.vo.MiniUserInfoQueryVo;
import gxmzu.gxmzuproject.entity.MiniUserInfo;
import gxmzu.gxmzuproject.config.common.BaseController;
import gxmzu.gxmzuproject.config.common.ApiResult;
import gxmzu.gxmzuproject.config.common.Paging;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Code534
 * @since 2022-08-03
 */
@Slf4j
@RestController
@RequestMapping("/miniUserInfo")
@Api(value = "小程序-登录-模块", tags = {"小程序-登录-模块"})
public class MiniUserInfoController extends BaseController {

    @Autowired
    private MiniUserInfoService miniUserInfoService;


    /**
    * 登录
    */
    @PostMapping("/login")
    @ApiOperation(value = "小程序用户登录对象",notes = "小程序用户登录对象")
    public ApiResult<MiniLoginInfoQueryVo> addMiniUserInfo(@Valid @RequestBody MiniCode2SessionQueryParam miniCode2SessionQueryParam) {

        MiniLoginInfoQueryVo miniUserInfo = miniUserInfoService.UserLogin(miniCode2SessionQueryParam);

        return ApiResult.ok(miniUserInfo);
    }

    /**
    * 修改
    */
    @PutMapping("/update")
    @ApiOperation(value = "修改MiniUserInfo对象",notes = "修改")
    public ApiResult<Boolean> updateMiniUserInfo(@Valid @RequestBody MiniUserInfo miniUserInfo) {
        boolean flag = miniUserInfoService.updateById(miniUserInfo);
        return ApiResult.result(flag);
    }

    /**
    * 删除
    */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除MiniUserInfo对象",notes = "删除")
    public ApiResult<Boolean> deleteMiniUserInfo(@PathVariable String id) {
        boolean flag = miniUserInfoService.removeById(id);
        return ApiResult.result(flag);
    }

    /**
    * 获取
    */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "获取MiniUserInfo对象详情",notes = "查看")
    public ApiResult<MiniUserInfoQueryVo> getMiniUserInfo(@PathVariable String id) {
        MiniUserInfoQueryVo miniUserInfoQueryVo = miniUserInfoService.getMiniUserInfoById(id);
        return ApiResult.ok(miniUserInfoQueryVo);
    }

    /**
     * 分页列表
     */
    @PostMapping("/getPageList")
    @ApiOperation(value = "获取MiniUserInfo分页列表",notes = "分页列表")
    public ApiResult<Paging<MiniUserInfoQueryVo>> getMiniUserInfoPageList(@Valid @RequestBody(required = false) MiniUserInfoQueryParam miniUserInfoQueryParam) {
        Paging<MiniUserInfoQueryVo> paging = miniUserInfoService.getMiniUserInfoPageList(miniUserInfoQueryParam);
        return ApiResult.ok(paging);
    }

}

